package com.lz.common;


import lombok.Data;

/**
 * @Description
 * @Author lz
 * @Version 1.0
 */
@Data
public class Result<T> {
    private boolean flag;//是否成功
    private Integer code;//返回码
    private String message;//返回消息
    private transient T data;//返回数据

    public static Integer getOkCode() {
        return 10000;
    }

    public Result(boolean flag, Integer code, String message, T data) {
        this.flag = flag;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result( Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result() {
        this.flag = true;
        this.code = ResultEnum.SUCCESS.getCode();
        this.message = "操作成功!";
    }

    public Result(boolean flag) {
        if (flag) {
            this.flag = true;
            this.code = 10000;
            this.message="success";
            this.data = null;
        }
        else {
            this.flag = false;
            this.code = 20000;
            this.message="error";
        }
    }

    @Override
    public String toString() {
        return "Result{" +
                "flag=" + flag +
                ", code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }




}
